﻿using Abp.Authorization;
using Abp.EntityFrameworkCore;
using Abp.Web.Models;
using Castle.DynamicProxy.Generators.Emitters.SimpleAST;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using SOEI.Solution.Application.Contracts.CommonOthers.WaterImage.Dtos;
using SOEI.Solution.Application.Contracts.Customized.WaterImage;
using SOEI.Solution.CommonOthers.WaterImage.DomainService;
using SOEI.Solution.CommonOthers.WaterImage.StructEntities;
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

namespace SOEI.Solution.CommonOthers.WaterImage
{
    [AbpAuthorize]
    [ApiExplorerSettings(GroupName = "Manager", IgnoreApi = false)]
    public class WaterImageAppService : SolutionAppServiceBase, IWaterImageAppService
    {

        public readonly IWaterImageManager _manager;

        public WaterImageAppService(IWaterImageManager manager)
        {
            _manager = manager;
        }

        /// <summary>获取已创建的水印图片
        /// </summary>
        public async Task<FileContentResult> GetWaterImage(WaterInputDto input)
        {
            var vParam = ObjectMapper.Map<WaterImageParam>(input);

            byte[] vData = await _manager.GetWaterImage(vParam);

            return new FileContentResult(vData, "image/png");
        }

        /// <summary>获取已创建的水印图片转换为Base64格式
        /// </summary>
        public async Task<string> GetWaterImageBase64(WaterInputDto input)
        {
            var vContent = await GetWaterImage(input);

            return Convert.ToBase64String(vContent.FileContents);
        }

        /// <summary>创建水印图片
        /// </summary>
        public async Task CreateWaterImage(WaterInputDto input)
        {
            var vParam = ObjectMapper.Map<WaterImageParam>(input);

            await _manager.CreateWaterImage(vParam);
        }

    }
}
